﻿using System;
using System.Web;
using System.Data;
using msBsc.AppLogic.DataAlc;
using System.IO;


namespace msBsc.WebUi
{
    public partial class wfGoodsImagesManager : msBsc.Cls.BPDealer
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
                //System.Random rd = new Random();
                //sRadom.Value = this.GetRadomString();
                LoadFileList("", "", "", "");
            }
        }

        private void BindControls()
        {
            if (!IsPostBack)
            {
            }
        }

        private void LoadFileList(string strParentId, string CurrPageNum, string strPageRowsCount, string strSort)
        {
            using (msBsc.AppLogic.DataAlc.CBizSysFile odataobj = new AppLogic.DataAlc.CBizSysFile())
            {
                DataSet ds = odataobj.SelectForCustomerImgMana(strParentId,msBsc.SvRef.UserInfo.Operator);

                string strjsontem1 = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", ""
                    , (CurrPageNum == string.Empty ? 1 : int.Parse(CurrPageNum))
                    , (strPageRowsCount == string.Empty ? 28 : int.Parse(strPageRowsCount))
                    , (strSort == string.Empty ? "IS_DIR DESC,REC_UPDATE_DT DESC" : strSort));
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                updateTableHtml( data);");
                this.SetContrlValue("txtCurrDirId", strParentId);
            }
        }

        private void toUpDIr()
        {
            using (msBsc.AppLogic.DataAlc.CBizSysFile odataobj = new AppLogic.DataAlc.CBizSysFile())
            {
                string strCurrid = this.GetParamHtValue("CURR_DIR_ID");
                DataSet ds = odataobj.DataObj.QueryBySQL("SELECT PARENT_FILE_ID FROM SYS_FILE WHERE FILE_ID='" + strCurrid + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    strCurrid = ds.Tables[0].Rows[0]["PARENT_FILE_ID"].ToString();
                    LoadFileList(strCurrid, "", "", "");
                }
            }
        }

        private void deleteFile()
        {
            System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            transactionOption.Timeout = new TimeSpan(0, 10, 0);
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            {
                using (msBsc.AppLogic.DataAlc.CBizSysFile odataobj = new AppLogic.DataAlc.CBizSysFile())
                {
                    odataobj.DeleteFilesByIds(this.GetParamHtValue("FILE_IDS"));
                    ts.Complete();
                }
            }
            LoadFileList(this.GetParamHtValue("CURR_DIR_ID"), "", "", "");
        }

        //重构基类的回调处理函数，以strAction属性来判断是什么类型的回调，该变量的值对应前台的ACTION参数，如：按钮的名称等
        public override void InitialByParam()
        {
            if (strAction == "LoadFileList")//根据传入的回调类型进行处理，这里响应编辑按钮
            {
                LoadFileList(this.GetParamHtValue("CURR_DIR_ID"), this.GetParamHtValue("NEW_PAGE_NUM"), this.GetParamHtValue("PAGE_ROW_COUNT"), this.GetParamHtValue("PAGE_ROW_SORT"));
            }
            else if (strAction == "deleteFile")//根据传入的回调类型进行处理，这里响应编辑按钮
            {
                deleteFile();
            }
            else if (strAction == "toUpDIr")//根据传入的回调类型进行处理，这里响应编辑按钮
            {
                toUpDIr();
            }
            //else if (strAction == "btnCancel")//根据传入的回调类型进行处理，这里响应编辑按钮
            //{
            //    SetItemStatus(this.GetParamHtValue("CHECK_ID"), "False");
            //    this.ExecJScript("btnDo('mFinder');");
            //}

            base.InitialByParam();
        } 

    }
}